import requests
from bs4 import BeautifulSoup
import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

def get_html(url):
    """获取网页内容"""
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
    try:
        response = requests.get(url, headers=headers)
        response.raise_for_status()  # 若请求失败，抛出异常
        return response.content.decode('utf-8')
    except requests.exceptions.RequestException as e:
        logging.error(f"请求失败：{e}")
        return None

def parse_html(html):
    """解析网页内容，提取数据"""
    soup = BeautifulSoup(html, 'html.parser')
    data = []
    for tr in soup.find_all('tbody')[0].find_all('tr'):
        tds = tr.find_all('td')
        row = [td.text.strip() for td in tds[:5]]  # 只选择前5列
        if len(row) == 0:
            continue
        data.append(row)
    return data
